package art.client.widgets;

import java.util.List;

import art.shared.entities.UserShared;

import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;

public class UserTable implements IsWidget {

	private CellTable<UserShared> cellTable = null;
	private List<UserShared> users = null;

	public UserTable(List<UserShared> users) {
		super();
		this.users = users;
		initWidget();
	}

	private void initWidget() {
		cellTable = new CellTable<UserShared>();
		addColumns();
		cellTable.setRowCount(users.size(), true);
		cellTable.setRowData(users);
	}

	@Override
	public Widget asWidget() {
		return cellTable;
	}

	private void addColumns() {
		TableColumnFactory factory = TableColumnFactory.getFactory();
		cellTable.addColumn(factory.getUserNicknameColumn(), "Nickname");
		cellTable.addColumn(factory.getUserNameColumn(), "Name");
		cellTable.addColumn(factory.getUserEmailColumn(), "Email");
		cellTable
				.addColumn(factory.getUserDateOfBirthColumn(), "Date of Birth");
		cellTable.addColumn(factory.getUserGenderColumn(), "Gender");
		//cellTable.addColumn(factory.getUserArtNumColumn(), "Number of Arts");
		cellTable.addColumn(factory.getUserDeleteButtonColumn());
	}

	public void updateData(List<UserShared> users) {
		this.users = users;
		cellTable.setRowData(users);
	}

}
